using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region EVMeeting

	/// <summary>
	/// EVMeeting object for NHibernate mapped table 'EVMeeting'.
	/// </summary>
	[Serializable]
	public class EVMeeting : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected Nullables.NullableDateTime _meetingDate;
		protected string _description;
		protected string _venue;
		protected string _visitingPurpose;
		protected string _content;
		protected Application _application;
		protected IList _eVMeetingAttendees;
		protected IList _actionPoints;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public EVMeeting() { }

		public EVMeeting( Nullables.NullableDateTime meetingDate, string description, string venue, string visitingPurpose, string content, Application application )
		{
			this._meetingDate = meetingDate;
			this._description = description;
			this._venue = venue;
			this._visitingPurpose = visitingPurpose;
			this._content = content;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public Nullables.NullableDateTime MeetingDate
		{
			get { return _meetingDate; }
			set { _meetingDate = value; }
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
				_description = value;
			}
		}

		public string Venue
		{
			get { return _venue; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Venue", value, value.ToString());
				_venue = value;
			}
		}

		public string VisitingPurpose
		{
			get { return _visitingPurpose; }
			set
			{
//				if ( value != null && value.Length > 4000)
//					throw new ArgumentOutOfRangeException("Invalid value for VisitingPurpose", value, value.ToString());
				_visitingPurpose = value;
			}
		}

		public string Content
		{
			get { return _content; }
			set
			{
//				if ( value != null && value.Length > 4000)
//					throw new ArgumentOutOfRangeException("Invalid value for Content", value, value.ToString());
				_content = value;
			}
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public IList EVMeetingAttendees
		{
			get
			{
				if (_eVMeetingAttendees==null)
				{
					_eVMeetingAttendees = new ArrayList();
				}
				return _eVMeetingAttendees;
			}
			set { _eVMeetingAttendees = value; }
		}

		public IList ActionPoints
		{
			get
			{
				if (_actionPoints==null)
				{
					_actionPoints = new ArrayList();
				}
				return _actionPoints;
			}
			set { _actionPoints = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is EVMeeting))
				throw new InvalidCastException("This object is not of type EVMeeting");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((EVMeeting)obj).Id);
					break;
				case "MeetingDate":
						relativeValue = ( this.MeetingDate != null ) ? this.MeetingDate.CompareTo(((EVMeeting)obj).MeetingDate) : -1;
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((EVMeeting)obj).Description) : -1;
					break;
				case "Venue":
						relativeValue = ( this.Venue != null ) ? this.Venue.CompareTo(((EVMeeting)obj).Venue) : -1;
					break;
				case "VisitingPurpose":
						relativeValue = ( this.VisitingPurpose != null ) ? this.VisitingPurpose.CompareTo(((EVMeeting)obj).VisitingPurpose) : -1;
					break;
				case "Content":
						relativeValue = ( this.Content != null ) ? this.Content.CompareTo(((EVMeeting)obj).Content) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (EVMeeting.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
